package com.lzy.concertticket.config;

import com.lzy.concertticket.interceptor.AuthInterceptor;
import com.lzy.concertticket.interceptor.FlowCountInterceptor;
import com.lzy.concertticket.interceptor.RequestResponseInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private FlowCountInterceptor flowCountInterceptor;
    @Autowired
    private AuthInterceptor authInterceptor;
    @Autowired
    private RequestResponseInterceptor requestResponseInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //  注册拦截器
        //  请求响应拦截器
        registry.addInterceptor(requestResponseInterceptor)
                .addPathPatterns("/**")
        ;
        //  流量记录拦截器
        registry.addInterceptor(flowCountInterceptor)
                .addPathPatterns("/**");
        //  登录拦截器
        registry.addInterceptor(authInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/auth/**");
    }
}
